package com.itxh.resource;

import java.io.InputStream;

/**
 * 该类封装的是classpath路径下的资源
 */
public class ClasspathResource implements Resource{
    private String location;

    public ClasspathResource(String location) {
        this.location = location;
    }

    @Override
    public InputStream getInputStream() {
        // web环境中配置classpath路径的信息，格式是classpath:xxx.xml
        if (location.indexOf("classpath:") > -1){
            location = location.substring(10);
        }
        if (location.indexOf("classpath*:") > -1){
            location = location.substring(11);
        }
        return this.getClass().getClassLoader().getResourceAsStream(location);
    }
}
